package com.ziyun.erp.web.modules.quoteFastPrintGroupPrice.controller;

import java.util.*;

import com.utility.StringUtils;
import com.ziyun.erp.common.utils.UserUtils;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ziyun.erp.modules.quoteFastPrintGroupPrice.entity.QuoteFastPrintGroupPriceEntity;
import com.ziyun.erp.modules.quoteFastPrintGroupPrice.service.QuoteFastPrintGroupPriceService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 快印报价组合计价表
 *
 * @author llc
 * @email 
 * @date 2018-09-14 15:23:53
 */
@RestController
@RequestMapping("quoteFastPrintGroupPrice/quotefastprintgroupprice")
public class QuoteFastPrintGroupPriceController {
    @Autowired
    private QuoteFastPrintGroupPriceService quoteFastPrintGroupPriceService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("quoteFastPrintGroupPrice:quotefastprintgroupprice:list")
    public R list(@RequestBody QuoteFastPrintGroupPriceEntity quoteFastPrintGroupPrice){
        quoteFastPrintGroupPrice.setFactoryId(1);
        //查看详情
        List<QuoteFastPrintGroupPriceEntity> fastPrintGroupPriceData =quoteFastPrintGroupPriceService.detail(quoteFastPrintGroupPrice);
        return R.ok().put("fastPrintGroupPriceData", fastPrintGroupPriceData);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("quoteFastPrintGroupPrice:quotefastprintgroupprice:info")
    public R info(@PathVariable("id") Integer id){
        QuoteFastPrintGroupPriceEntity quoteFastPrintGroupPrice = quoteFastPrintGroupPriceService.selectById(id);

        return R.ok().put("quoteFastPrintGroupPrice", quoteFastPrintGroupPrice);
    }

   /* *//**
     * 保存
     *//*
    @RequestMapping("/save")
    @RequiresPermissions("quoteFastPrintGroupPrice:quotefastprintgroupprice:save")
    public R save(@RequestBody QuoteFastPrintGroupPriceEntity quoteFastPrintGroupPrice){
       *//* quoteFastPrintGroupPriceService.insert(quoteFastPrintGroupPrice);*//*

        return R.ok();
    }*/


     /**
     * 批量保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody   List<QuoteFastPrintGroupPriceEntity>  groupPriceList){
        for (int i=0;i<groupPriceList.size();i++){
            QuoteFastPrintGroupPriceEntity quoteFastPrintGroupPrice=  groupPriceList.get(i);
            //设置参数
            quoteFastPrintGroupPrice.setUpdateDate(new Date());
            quoteFastPrintGroupPrice.setUpdateUser(UserUtils.getCurentUser().getUsername());
        }
        //批量更新
        quoteFastPrintGroupPriceService.updateBatchById(groupPriceList);
        return R.ok();
    }


    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("quoteFastPrintGroupPrice:quotefastprintgroupprice:update")
    public R update(@RequestBody QuoteFastPrintGroupPriceEntity quoteFastPrintGroupPrice){
        ValidatorUtils.validateEntity(quoteFastPrintGroupPrice);
        quoteFastPrintGroupPriceService.updateAllColumnById(quoteFastPrintGroupPrice);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    /*@RequiresPermissions("quoteFastPrintGroupPrice:quotefastprintgroupprice:delete")*/
    public R delete(@RequestBody Integer[] ids){
        String updateName = UserUtils.getCurentUser().getUsername();
        return quoteFastPrintGroupPriceService.updateDelFlag(Arrays.asList(ids),updateName);
    }

    /**
     * 初始化已存在的颜色和材料列表
     */
    @RequestMapping("/fastPrintMaterialList")
    public R getFastPrintMaterialList(@RequestParam Map<String, Object> params){
        params.put("factory_id",1);
        List<QuoteFastPrintGroupPriceEntity> fastPrintMaterialData=quoteFastPrintGroupPriceService.getFastPrintMaterialList(params);
        return R.ok().put("fastPrintMaterialData", fastPrintMaterialData);
    }

    /**
     * 查找已存在的颜色和材料列表
     */
    @RequestMapping("/queryfastPrintMaterialList")
    public R queryFastPrintMaterialList(@RequestBody QuoteFastPrintGroupPriceEntity quoteFastPrintGroupPrice){
        Map<String,Object> params=new HashMap<String,Object>();
        if(StringUtils.isNotBlank(quoteFastPrintGroupPrice.getOptionName())){
            params.put("optionName",quoteFastPrintGroupPrice.getOptionName().trim());
        }
       if(StringUtils.isNotBlank(quoteFastPrintGroupPrice.getColour())){
            params.put("colour",quoteFastPrintGroupPrice.getColour().trim());
        }
        params.put("factory_id",1);
        List<QuoteFastPrintGroupPriceEntity> fastPrintMaterialData=quoteFastPrintGroupPriceService.getFastPrintMaterialList(params);
        return R.ok().put("fastPrintMaterialData", fastPrintMaterialData);
    }

}
